<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\admin\model\goods\Order;
use app\common\controller\Api;
use app\common\controller\Payment;
use think\Controller;
use think\Db;
use think\Request;


class Fishinggroundcommentpraises extends Api
{
    private static $model;
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';


    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new \app\common\model\FishingGroundCommentPraises();
    }

    /**
     * 野钓场评论点赞
     */
    public function create()
    {
        $commentId = input('comment_id');
        if (!$commentId) {
            $this->error('参数缺失！');
        }

        $where = [
            'user_id' => $this->auth->id,
            'comment_id' => $commentId,
        ];

        $row_info = self::$model->where($where)->find();
        if (!$row_info) {
            $pdata = [
                'user_id' => $this->auth->id,
                'comment_id' => $commentId,
            ];

            $res = self::$model->create($pdata);
            if (!$res) {
                $this->error('点赞失败！');
            }

            \app\common\model\UserScoreLog::praiseBonus($this->auth->id);

            $this->success('点赞成功！');
        } else {
            $res = self::$model->where('id', $row_info->id)->delete();
            if (!$res) {
                $this->error('取消点赞失败！');
            }

            \app\common\model\UserScoreLog::praiseBonus($this->auth->id, 0);

            $this->success('取消点赞成功！');
        }
    }
}
